home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
cuj9205.zip
/
1005052B
< prev
next >
Wrap
Text File
|
1992-06-02
|
1KB
|
37 lines
Listing 4. Filter with circular buffer
/* Filters the vector, v, of input values, putting the
* results back in the same vector.
*/
void filter(Filter *f, double *v, int length)
{
/* Making a local copy saves execution time */
CircularBuffer y = *(f->y);
/* Loop through the vector values */
for(; length--; v++)
{
double
sum = *v, /* becomes filter output */
*c = f->coef;
int k = f->order, /* The number of coefficients */
i = y.index; /* Index to previous outputs */
/* Loop through filter coefficients */
for(; k--; c++)
{
i = (i - 1) & y.mask;
sum -= *c * y.buffer[i];
}
/* Save output for next data point */
y.buffer[y.index] = sum;
y.index = (y.index + 1) & y.mask;
*v = sum; /* Set output value */
}
/* Store the local copy back in the filter structure */
*(f->y) = y;
}